<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/adminHead.jsp"%>
<script type="text/javascript">
var pagingDTO={};
pagingDTO.userId = '<c:out value="${user.userId }"/>';
var markerSetting={
		'buy':{},
		'use':{}
};
markerSetting['buy']= {
  		paging:{}
  };
markerSetting['use']= {
  		paging:{}
  };
var _this = this;
$(function() {
  	_this.buyPoint = tableSync('tbl_buy');
  	_this.usePoint = tableSync('tbl_use');
  	init();
	buyTbl();
	useTbl();
	});
	
function init() {
		markerSetting['buy'].paging.page = 1;
	markerSetting['buy'].paging.totalPage ='<c:out value="${buyTotal}"/>';
	markerSetting['buy'].paging.nowSeq = 1;
	markerSetting['buy'].paging.userId = '<c:out value="${user.userId }"/>';
	
	markerSetting['use'].paging.page = 1;
	markerSetting['use'].paging.totalPage ='<c:out value="${useTotal}"/>';
	markerSetting['use'].paging.nowSeq = 1;
	markerSetting['use'].paging.userId = '<c:out value="${user.userId }"/>';
}
	
var pagingUseDTO={};
pagingUseDTO.userId = '<c:out value="${user.userId }"/>';
	
var buyTbl = function(start){
  	var url='/admin/memberViewPointBuy.json';
//   	pagingDTO.start = start||0;
	AjaxPost(url, markerSetting['buy'].paging, function(data){
	jsonLog(data.buyPoint);
		$.each(data.buyPoint,function(index, value){
			value.pointRegiTime = formatter.dateFormatYYYYMMDDHHMMSS2(new Date(value.pointRegiTime));
		});
		_this.buyPoint.tableAutoSync(data.buyPoint);
		markerSetting['buy'].paging.totalPage= data.buyTotal;
		makePaging();
	});
};
var useTbl = function(start){
  	var url='/admin/memberViewPointUse.json';
//   	pagingUseDTO.start = start||0;
	
	AjaxPost(url, markerSetting['use'].paging, function(data){
	jsonLog(data.usePoint);
		$.each(data.usePoint,function(index, value){
			value.pointRegiTime = formatter.dateFormatYYYYMMDDHHMMSS2(new Date(value.pointRegiTime));
		});
		_this.usePoint.tableAutoSync(data.usePoint);
		markerSetting['use'].paging.totalPage= data.useTotal;
		makeUsePaging();
	});
};




function makePaging() {
	$('#pagenation').html("");
		var totalPage = markerSetting['buy'].paging.totalPage;
		var nowPage = markerSetting['buy'].paging.page;
		var html='';
		var setFunctionName='';
		var index=(nowPage-3);
		var indexCount=0;
		
		var endPage = totalPage / 3;
		if (totalPage % 3 > 0) {
			endPage = endPage + 1;
		}
		if(index>1){
			html+='<a onclick="changePaging(1,\'before\''+')" onFocus=this.blur()><img src="${imgUrl }/btn_first.jpg"/ alt=처음 align=absmiddle style="/cursor:hand;/"></a>';
			html+='<a onclick="changePaging('+index+',\'before\''+')" onFocus=this.blur()><img src="${imgUrl }/btn_prev.jpg"/  alt=이전 align=absmiddle style="/cursor:hand;/"></a>&nbsp;&nbsp;';
		}
// 		debugger;
//		//logs('totalPage/20 = '+totalPage/20);
		for(;index<=endPage;index++){
			if((index)==nowPage){
				setFunctionName='';
			}else{
				setFunctionName=' onclick="changePaging('+index+')"';
			}
			
			if(index>0){
					
				if(index == nowPage) {
					html+='<a '+setFunctionName+'><b>'+index+'</b></a>&nbsp;';
				} else {
					html+='<a '+setFunctionName+' style=cursor:hand;>'+index+'</a>&nbsp;';
				}	
				
				indexCount++;
			}
			if(indexCount>2){
				html+='<a onclick="changePaging('+index+',\'after\''+')" onFocus=this.blur()><img src="${imgUrl }/btn_next.jpg"/  alt=다음 align=absmiddle style="/cursor:hand;/"></a>';
				html+='<a onclick="changePaging('+totalPage+',\'after\''+')" onFocus=this.blur()><img src="${imgUrl }/btn_last.jpg"/  alt=맨끝 align=absmiddle style="/cursor:hand;/"></a>';
				break;
			}
			
		}
		$('#pagenation').html(html);
}

function changePaging(index, option){
		if(option==null){
			logs(', index = '+index);
			
			markerSetting['buy'].paging.page=index;
			markerSetting['buy'].paging.start=0;
			markerSetting['buy'].paging.end=0;
			buyTbl();
		}else{
			if(option=='before'){
				var next = index-9;
				while(next<=0){
					next++;
				}
				logs('next = '+next+', index = '+index);
				markerSetting['buy'].paging.page=next;
				markerSetting['buy'].paging.start=0;
				markerSetting['buy'].paging.end=0;
				buyTbl();
			}else if(option=='after'){
				var next = index+9;
				while(next>=(markerSetting['buy'].paging.totalPage/10)+1){
					next--;
				}
				logs('next = '+next+', index = '+index);
				markerSetting['buy'].paging.page=next;
				markerSetting['buy'].paging.start=0;
				markerSetting['buy'].paging.end=0;
				buyTbl();
			}
		}
	}
	
	
	

function makeUsePaging() {
	$('#pagenationUse').html("");
		var totalPage = markerSetting['use'].paging.totalPage;
		var nowPage = markerSetting['use'].paging.page;
		var html='';
		var setFunctionName='';
		var index=(nowPage-3);
		var indexCount=0;
		
		var endPage = totalPage / 3;
		if (totalPage % 3 > 0) {
			endPage = endPage + 1;
		}
		if(index>1){
			html+='<a onclick="changeUsePaging(1,\'before\''+')" onFocus=this.blur()><img src="${imgUrl }/btn_first.jpg"/ alt=처음 align=absmiddle style="/cursor:hand;/"></a>';
			html+='<a onclick="changeUsePaging('+index+',\'before\''+')" onFocus=this.blur()><img src="${imgUrl }/btn_prev.jpg"/  alt=이전 align=absmiddle style="/cursor:hand;/"></a>&nbsp;&nbsp;';
		}
// 		debugger;
//		//logs('totalPage/20 = '+totalPage/20);
		for(;index<=endPage;index++){
			if((index)==nowPage){
				setFunctionName='';
			}else{
				setFunctionName=' onclick="changeUsePaging('+index+')"';
			}
			
			if(index>0){
					
				if(index == nowPage) {
					html+='<a '+setFunctionName+'><b>'+index+'</b></a>&nbsp;';
				} else {
					html+='<a '+setFunctionName+' style=cursor:hand;>'+index+'</a>&nbsp;';
				}	
				
				indexCount++;
			}
			if(indexCount>2){
				html+='<a onclick="changeUsePaging('+index+',\'after\''+')" onFocus=this.blur()><img src="${imgUrl }/btn_next.jpg"/  alt=다음 align=absmiddle style="/cursor:hand;/"></a>';
				html+='<a onclick="changeUsePaging('+totalPage+',\'after\''+')" onFocus=this.blur()><img src="${imgUrl }/btn_last.jpg"/  alt=맨끝 align=absmiddle style="/cursor:hand;/"></a>';
				break;
			}
			
		}
		$('#pagenationUse').html(html);
}

function changeUsePaging(index, option){
		if(option==null){
			logs(', index = '+index);
			
			markerSetting['use'].paging.page=index;
			markerSetting['use'].paging.start=0;
			markerSetting['use'].paging.end=0;
			useTbl();
		}else{
			if(option=='before'){
				var next = index-9;
				while(next<=0){
					next++;
				}
				logs('next = '+next+', index = '+index);
				markerSetting['use'].paging.page=next;
				markerSetting['use'].paging.start=0;
				markerSetting['use'].paging.end=0;
				useTbl();
			}else if(option=='after'){
				var next = index+9;
				while(next>=(markerSetting['use'].paging.totalPage/10)+1){
					next--;
				}
				logs('next = '+next+', index = '+index);
				markerSetting['use'].paging.page=next;
				markerSetting['use'].paging.start=0;
				markerSetting['use'].paging.end=0;
				useTbl();
			}
		}
	}

var deleteUser = function(){
	var myDecision = confirm('정말 삭제 하시겠습니까?'); 
	if(myDecision){
		var url='/admin/memberDeleteUser.json';
		AjaxPost(url, markerSetting['buy'].paging, function(data){
			location.replace("/admin/adminMemberMain");    
			});
	}
	else{ 
		return; 
		}
}
</script>
<LINK href="${cssUrl }/admin.css" rel="stylesheet" type="text/css">
    <TR>
        <TD height="%" valign="top">
            <TABLE border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">
                <TBODY>
                    <TR>
                        <TD align="right" height="%" valign="top" width="186">
                            <TABLE border="0" cellpadding="0" cellspacing="0" height="100%" width="176">
                                <TBODY>
                                    <TR>
                                        <TD height="53">
                                            <IMG src="${imgUrl}/left_top_title.gif"></TD>
                                        </TR>
                                        <TR>
                                            <TD background="${imgUrl}/left_bg.gif" height="%" style="padding: 5px 0px 0px 5px;" valign="top">
                                                <TABLE border="0" cellpadding="0" cellspacing="0" style="margin-top: 10px;" width="150">
                                                    <TBODY>
                                                        <tr>
                                                            <td height="25"><img align="absmiddle" border="0" src="${imgUrl}/left_icon.gif"/><a class="leftmenu" href="/admin/adminMemberMain">회원관리</a></td>
                                                        </tr>
                                                    </TBODY>
                                                </TABLE>
                                            </TD>
                                        </TR>
                                    </TBODY>
                                </TABLE>
                            </TD>
                            <TD align="right" style="padding: 20px 10px 0px 0px;" valign="top" width="%">
                                <TABLE border="0" cellpadding="0" cellspacing="0" width="97%">
                                    <TBODY>
                                        <TR>
                                            <TD align="left" background="${imgUrl}/title_bg.gif" class="admin_title" valign="middle">
                                                <IMG align="absmiddle" src="${imgUrl}/title_icon.gif">회원관리
                                                </TD>
                                            </TR>
                                            <TR>
                                                <TD height="20">&nbsp;</TD>
                                            </TR>
                                            <TR>
                                                <TD>
                                                    <TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
                                                        <tr>
                                                            <td colspan="2">
                                                                <table bgcolor="#d9d9d9" border="0" cellpadding="0" cellspacing="1" width="100%">
                                                                    <tr>
                                                                        <td bgcolor="#3f8bc9" colspan="4" height="1"></td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td align="center" bgcolor="#eff3fa" class="top_blue3" width="10%">회원가입일</td>
                                                                        <td align="left" bgcolor="#ffffff" style="padding-left: 10px;"><c:out value="${user.regDateStr }"/></td>
                                                                        <td align="center" bgcolor="#eff3fa" class="top_blue3" width="10%">회원상태</td>
                                                                        <td align="left" bgcolor="#ffffff" style="padding-left: 10px;"><c:out value="${user.statusStr }"/></td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td align="center" bgcolor="#eff3fa" class="top_blue3">이름</td>
                                                                        <td align="left" bgcolor="#ffffff" style="padding-left: 10px;" colspan="3"><c:out value="${user.userName }"/></td>
                                                                        <!-- <td align="center" bgcolor="#eff3fa" class="top_blue3">영문명</td>
                                                                        <td align="left" bgcolor="#ffffff" style="padding-left: 10px;">test</td> -->
                                                                    </tr>
                                                                    <tr>
                                                                        <td align="center" bgcolor="#eff3fa" class="top_blue3">아이디</td>
                                                                        <td align="left" bgcolor="#ffffff" style="padding-left: 10px;"><c:out value="${user.userId }"/></td>
                                                                        <td align="center" bgcolor="#eff3fa" class="top_blue3">패스워드</td>
                                                                        <td align="left" bgcolor="#ffffff" style="padding-left: 10px;"><c:out value="${user.userPw }"/></td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td align="center" bgcolor="#eff3fa" class="top_blue3">휴대폰번호</td>
                                                                        <td align="left" bgcolor="#ffffff" style="padding-left: 10px;"><c:out value="${user.cellPhone }"/></td>
                                                                        <td align="center" bgcolor="#eff3fa" class="top_blue3">이메일</td>
                                                                        <td align="left" bgcolor="#ffffff" style="padding-left: 10px;"><c:out value="${user.email }"/></td>
                                                                    </tr>
                                                                </table>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td align="left">
                                                                <a href="/admin/adminMemberMain">
                                                                    <img border="0" src="${imgUrl}/btn_list.gif"></a>
                                                                </td>
                                                                <td align="right" height="35">
                                                                    <a href="/admin/member_write?userId=<c:out value="${user.userId }"/>">
                                                                        <img border="0" src="${imgUrl}/btn_modify.gif"></a>
                                                                        <a href="#." onclick="deleteUser()">
                                                                            <img border="0" hspace="3" src="${imgUrl}/btn_del.gif"></a>
                                                                        </td>
                                                                    </tr>
                                                                </TABLE>
                                                            </TD>
                                                        </TR>
                                                        <tr>
                                                            <td height="40"></td>
                                                        </tr>
                                                        <script>
                                                            function tab1(no) {
                                                                $("#tab1,#tab2").css('display', 'none');
                                                                $("#tab" + no).show();
                                                            }
                                                        </script>
                                                        <table border="0" cellpadding="0" cellspacing="0" id="tab1" width="97%">
                                                            <TR>
                                                                <TD align="left" background="${imgUrl}/title_bg.gif" class="admin_title" valign="middle">
                                                                    <IMG align="absmiddle" src="${imgUrl}/title_icon.gif"><a href="javascript:tab1(1);">구매포인트</a>
                                                                        / 
                                                                        <a href="javascript:tab1(2);"><font color="#808080">사용포인트</font></a>
                                                                    </TD>
                                                                </TR>
                                                                <TR>
                                                                    <tr>
                                                                        <td>
                                                                            <TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
                                                                                <TBODY>
                                                                                    <TR>
                                                                                        <TD>
                                                                                            <TABLE id="" bgcolor="#d9d9d9" border="0" cellpadding="0" cellspacing="1" width="100%">
                                                                                                <TBODY>
                                                                                                    <TR>
                                                                                                        <TD bgcolor="#3f8bc9" colspan="7" height="1"></TD>
                                                                                                    </TR>
                                                                                                    <TR>
                                                                                                        <TD align="center" bgcolor="#eff3fa" class="top_blue3" width="25%">번호</TD>
                                                                                                        <TD align="center" bgcolor="#eff3fa" class="top_blue3" width="25%">아이디</TD>
                                                                                                        <TD align="center" bgcolor="#eff3fa" class="top_blue3" width="25%">적립포인트</TD>
                                                                                                        <TD align="center" bgcolor="#eff3fa" class="top_blue3" width="25%">포인트적립일</TD>
                                                                                                    </TR>
                                                                                                    </TBODY>
                                                                                            </table>
                                                                                            <TABLE id="tbl_buy" bgcolor="#d9d9d9" border="0" cellpadding="0" cellspacing="1" width="100%">
                                                                                                <TBODY>
                                                                                                    <tr>
                                                                                                        <td align="center" bgcolor="#ffffff" class="list_dark" width="25%" id="seq">3</td>
                                                                                                        <td align="center" bgcolor="#ffffff" class="list_dark" width="25%"><a href="#" id="userId">test</a></td>
                                                                                                        <td align="center" bgcolor="#ffffff" class="list_dark" width="25%" id="point">test</td>
                                                                                                        <td align="center" bgcolor="#ffffff" class="list_dark" width="25%" id="pointRegiTime">2014-08-22
                                                                                                            18:23:56</td>
                                                                                                    </tr>
                                                                                                </TBODY>
                                                                                            </TABLE>
                                                                                        </TD>
                                                                                    </TR>
                                                                                    <TR>
                                                                                        <TD align="right" colspan="7" height="30" valign="bottom">
                                                                                            <A href="#">
                                                                                                <%-- <IMG src="${imgUrl}/btn_write.gif"></A> --%>
                                                                                            </TD>
                                                                                        </TR>
                                                                                        <TR>
                                                                                            <TD align="center" colspan="7" height="35" valign="middle">
                                                                                                <div id="pagenation"></div>
                                                                                                </TD>
                                                                                            </TR>
                                                                                            <TR>
                                                                                                <TD align="center" colspan="7">
                                                                                                    <FORM method="post" name="fsearch" style="margin: 0px;">
                                                                                                        <TABLE border="0" cellpadding="0" cellspacing="0">
                                                                                                            <TBODY>
                                                                                                                <TR>
                                                                                                                    <TD align="middle" style="padding: 3px 0px 0px 5px;" valign="middle">
                                                                                                                        <SELECT class="inputText" id="search_type" name="search_type"><OPTION selected value="tlt">제목</OPTION>
                                                                                                                            <OPTION value="content">본문</OPTION>
                                                                                                                        </SELECT>
                                                                                                                        <INPUT class="inputText" maxlength="25" name="search_word" size="30" type="text" value=></TD>
                                                                                                                        <TD align="right" style="padding-left: 5px;" valign="middle">
                                                                                                                            <INPUT align="absmiddle" hspace="3" src="${imgUrl}/n_search.gif" style="cursor: hand;" type="image"></TD>
                                                                                                                        </TR>
                                                                                                                    </TBODY>
                                                                                                                </TABLE>
                                                                                                            </FORM>
                                                                                                        </TD>
                                                                                                    </TR>
                                                                                                    <TR>
                                                                                                        <TD>&nbsp;</TD>
                                                                                                    </TR>
                                                                                                </TBODY>
                                                                                            </TABLE>
                                                                                        </td>
                                                                                    </tr>
                                                                                </table>
                                                                                <table border="0" cellpadding="0" cellspacing="0" id="tab2" style="display: none;" width="97%">
                                                                                    <TR>
                                                                                        <TD align="left" background="${imgUrl}/title_bg.gif" class="admin_title" valign="middle">
                                                                                            <IMG align="absmiddle" src="${imgUrl}/title_icon.gif">
                                                                                                <a href="javascript:tab1(1);"><font color="#808080">구매포인트</font></a>
                                                                                                / 
                                                                                                <a href="javascript:tab1(2);">사용포인트</a></TD>
                                                                                        </TR>
                                                                                        <TR>
                                                                                            <tr>
                                                                                                <td>
                                                                                                    <TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
                                                                                                        <TBODY>
                                                                                                            <TR>
                                                                                                                <TD>
                                                                                                                    <form>
                                                                                                                        <TABLE bgcolor="#d9d9d9" border="0" cellpadding="0" cellspacing="1" width="100%">
                                                                                                                            <TBODY>
                                                                                                                                <TR>
                                                                                                                                    <TD bgcolor="#3f8bc9" colspan="7" height="1"></TD>
                                                                                                                                </TR>
                                                                                                                                <TR>
                                                                                                                                    <TD align="center" bgcolor="#eff3fa" class="top_blue3" width="25%">번호</TD>
                                                                                                                                    <TD align="center" bgcolor="#eff3fa" class="top_blue3" width="25%">아이디</TD>
                                                                                                                                    <TD align="center" bgcolor="#eff3fa" class="top_blue3" width="25%">시용포인트</TD>
                                                                                                                                    <TD align="center" bgcolor="#eff3fa" class="top_blue3" width="25%">포인트사용일</TD>
                                                                                                                                </TR>
                                                                                                                                </tbody>
                                                                                                                                </table>
                                                           		                            <TABLE id="tbl_use" bgcolor="#d9d9d9" border="0" cellpadding="0" cellspacing="1" width="100%">
                                                                                                <TBODY>
                                                                                                    <tr>
                                                                                                        <td align="center" bgcolor="#ffffff" class="list_dark" width="25%" id="seq">3</td>
                                                                                                        <td align="center" bgcolor="#ffffff" class="list_dark" width="25%"><a href="#" id="userId">test</a></td>
                                                                                                        <td align="center" bgcolor="#ffffff" class="list_dark" width="25%" id="point">test</td>
                                                                                                        <td align="center" bgcolor="#ffffff" class="list_dark" width="25%" id="pointRegiTime">2014-08-22
                                                                                                            18:23:56</td>
                                                                                                    </tr>
                                                                                                </TBODY>
                                                                                            </TABLE>
                                                                                                                    </FORM>
                                                                                                                </TD>
                                                                                                            </TR>
                                                                                                            <TR>
                                                                                                                <TD align="right" colspan="7" height="30" valign="bottom">
                                                                                                                    <A href="#">
                                                                                                                        <%-- <IMG src="${imgUrl}/btn_write.gif"></A> --%>
                                                                                                                    </TD>
                                                                                                                </TR>
                                                                                                                <TR>
                                                                                                                    <TD align="center" colspan="7" height="35" valign="middle">
                                                                                                                        <div id="pagenationUse"></div>
                                                                                                                        </TD>
                                                                                                                    </TR>
                                                                                                                    <TR>
                                                                                                                        <TD align="center" colspan="7">
                                                                                                                            <FORM method="post" name="fsearch" style="margin: 0px;">
                                                                                                                                <TABLE border="0" cellpadding="0" cellspacing="0">
                                                                                                                                    <TBODY>
                                                                                                                                        <TR>
                                                                                                                                            <TD align="middle" style="padding: 3px 0px 0px 5px;" valign="middle">
                                                                                                                                                <SELECT class="inputText" id="search_type" name="search_type">
                                                                                                                                                    <OPTION selected value="tlt">제목</OPTION>
                                                                                                                                                    <OPTION value="content">본문</OPTION>
                                                                                                                                                </SELECT>
                                                                                                                                                <INPUT class="inputText" maxlength="25" name="search_word" size="30" type="text" value=></TD>
                                                                                                                                                <TD align="right" style="padding-left: 5px;" valign="middle">
                                                                                                                                                    <INPUT align="absmiddle" hspace="3" src="${imgUrl}/n_search.gif" style="cursor: hand;" type="image"></TD>
                                                                                                                                                </TR>
                                                                                                                                            </TBODY>
                                                                                                                                        </TABLE>
                                                                                                                                    </FORM>
                                                                                                                                </TD>
                                                                                                                            </TR>
                                                                                                                            <TR>
                                                                                                                                <TD>&nbsp;</TD>
                                                                                                                            </TR>
                                                                                                                        </TBODY>
                                                                                                                    </TABLE>
                                                                                                                </td>
                                                                                                            </tr>
                                                                                                        </table>
                                                                                                    </TBODY>
                                                                                                </TABLE>
                                                                                            </TD>
                                                                                        </TR>
                                                                                    </TBODY>
                                                                                </TABLE>
                                                                            </TD>
                                                                        </TR>
                                                                    </TBODY>
                                                                </TABLE>
                                                            </BODY>
                                                        </HTML>